package com.sinoglobal.wallet.adapter;

import java.util.Map;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.callback.BitmapLoadCallBack;
import com.lidroid.xutils.bitmap.callback.BitmapLoadFrom;
import com.sinoglobal.wallet.R;
import com.sinoglobal.wallet.app.SinoAppState;
import com.sinoglobal.wallet.app.SinoConstans;
import com.sinoglobal.wallet.entity.W_MyBankVo;

public class W_MyBankAdapter extends W_SinoBaseSimpleAdapter<W_MyBankVo>{
	private Context mContext;
	BitmapUtils bitmapUtils;
	
	public W_MyBankAdapter(Context mContext) {
		super(mContext);
		this.mContext = mContext;
		 bitmapUtils = new BitmapUtils(mContext);
	  bitmapUtils.configDefaultLoadingImage(R.drawable.bank_icon_default);
		bitmapUtils.configDefaultLoadFailedImage(R.drawable.bank_icon_default);
	}

	@Override
	public void findViews(Map<java.lang.String, View> widgets, int position, View convertView) {
		ImageView myBankItem_img = (ImageView) convertView.findViewById(R.id.myBankItem_img);
		TextView myBankItem_NameTv = (TextView) convertView.findViewById(R.id.myBankItem_NameTv);
		TextView myBankItem_endNumTv = (TextView) convertView.findViewById(R.id.myBankItem_endNumTv);
		widgets.put("myBankItem_img", myBankItem_img);
		widgets.put("myBankItem_NameTv", myBankItem_NameTv);
		widgets.put("myBankItem_endNumTv", myBankItem_endNumTv);
	}
	

	@Override
	public void setValues(View convertView, ViewHolder holder, Map<String, View> widgets, int position) {
		final ImageView myBankItem_img = (ImageView) widgets.get("myBankItem_img");
		TextView myBankItem_NameTv = (TextView) widgets.get("myBankItem_NameTv");
		TextView myBankItem_endNumTv = (TextView) widgets.get("myBankItem_endNumTv");
		
		W_MyBankVo balance = (W_MyBankVo) getItem(position);

//		if(balance.getBankIcon().toString().endsWith("")){
//			myBankItem_img.setBackgroundResource(R.drawable.ic_launcher);
//		}
		bitmapUtils.display(myBankItem_img, SinoConstans.IMAGE_URL + balance.getBankIcon());
		
		myBankItem_NameTv.setText(balance.getBankName());
		if(balance.getCardSn()!=null){
			myBankItem_endNumTv.setText("(尾号" + balance.getCardSn().substring(balance.getCardSn().toCharArray().length-4, 
					balance.getCardSn().toCharArray().length) + ")");
		}
		
	}

	@Override
	public View setAdapterLayout(LayoutInflater inflater, int position) {
		return inflater.inflate(R.layout.wallet_minebank_activity_item, null);
	}
	
}
